package asteroids.model.programs.Statement;

import asteroids.model.programs.Program;
import asteroids.model.programs.Type;
import asteroids.model.programs.Expression.IBooleanExpression;
import asteroids.model.programs.Expression.Expression;
import asteroids.model.programs.Expression.IDoubleExpression;
import asteroids.model.programs.Expression.IEntityExpression;
import asteroids.model.programs.Expression.VariableLiteral;


/**
* 
* @version 0.3
* @author  Tandan Sunil, Van Deun Luca
*
*/
public class PrintLiteral extends ShortStatement {

	public PrintLiteral(int line, int column, Expression exp) {
		super(line, column,exp);
		
	}

	@Override
	public void execute(Program program) {

		if(getExpression() instanceof VariableLiteral){
			String variableName =  ((VariableLiteral) getExpression()).getVariableName();
			VariableLiteral vl = program.getVariableOf(variableName);
			setExpression(vl);
		}
		if(getExpression().getType().getType()==Type.AllType.BOOLEAN)
			System.out.println(((IBooleanExpression)getExpression()).getBoolean());
			
		
		else if(getExpression().getType().getType()==Type.AllType.DOUBLE)
			System.out.println(((IDoubleExpression)getExpression()).getValue());
		
		else
			System.out.println(((IEntityExpression) getExpression()).getEntity());
		
		setExecuted(true);
		
	}
	
}
